import * as storage from '@/utils/storage'

export const getLocalStorage = (key:string) => {
	const data: any = uni.getStorageSync(key)
	if(typeof(data) == 'string') {
		try {
			const obj = JSON.parse(data)
			return typeof(obj) == 'object'?JSON.parse(data):data
		} catch(e) {
			return data
		}
	} else {
		return data
	}
  
}

export const setLocalStorage = (key:string, value:any) => {
	const data: any = typeof(value) == 'object'?JSON.stringify(value):value
	uni.setStorageSync(key, data)
	
}


export const clearAllStorage = (authStore:any, goodsHistoryStore:any) => {
  	authStore.setToken('')
  	authStore.setExpiresIn('')
	authStore.setInfo({
		user:null,
		permissions:null,
		rolePermissions:null,
		roles:null,
		isItCertified:''
	})
	goodsHistoryStore.delHistoryAll()
  	storage.setLocalStorage('warehouseIn', null)
  	storage.setLocalStorage('warehouseOut', null)
}